﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.DocManger;
using Jzy.Model.DocManger;
using Frame.Lib.Core.Right;
using Frame.Lib.Common;
using Frame.Lib.Enums;
using Frame.Lib.Utilities;


namespace Jzy.Web.DocManager.Document
{
    public partial class Detail : PageDetail
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DispInfo();
            }
            JSUtil.SetDivHeight("main", 45);
        }

        private void DispInfo()
        {
            DocumentBO doc = new DocumentBO();

            DocumentInfo info = doc.GetInfo(this.PKID);

            litName.Text = info.Name;
            litInputTime.Text = info.InputTime.ToString("yyyy年MM月dd日hh:mm");
            litClickCount.Text = info.ClickCount.ToString();
            litCreatorName.Text = info.CreatorName;
            litContent.Text = info.Content;

            rptAttach.DataSource = info.Attachs;
            rptAttach.DataBind();

            rptPicture.DataSource = info.Pictures;
            rptPicture.DataBind();

            info.ClickCount += 1;

            doc.Save(info, false);


            //判断有没有编辑权限

            RecordRightBO right = new RecordRightBO("DocRight");

            bool flag = right.HaveRight(int.Parse(this.PKID), AppSession.UserID, RecordRightName.Edit, RightOwnerType.User);

            if (AppSession.UserID == info.CreatorID || AppSession.UserID == Constants.ADMIN_ID || flag)
            {
                lnkEdit.HRef = "Edit.aspx?ID=" + this.Encrypt(info.ID);
            }
            else
            {
                liEdit.Visible = false;
            }


        }
    }
}
